package ru.spb.osll.myfit.fixtures;

import java.util.Vector;

import org.apache.log4j.Logger;

import ru.spb.osll.myfit.common.GlobalContainer;
import ru.spb.osll.myfit.common.Page;
import ru.spb.osll.myfit.common.PageElement;
import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableCell;
import ru.spb.osll.myfit.common.TableCellResult;
import ru.spb.osll.myfit.fixtures.base.OneLineFixture;
import ru.spb.osll.myfit.fixtures.log.MyFitLogger;

public class VerifyTestResultOkFixture extends OneLineFixture {
	private Logger Log = MyFitLogger.getLogger(VerifyTestResultOkFixture.class); 
    
	public boolean verifyTestResultOk() {
		
		boolean result = true;
		Page testResult = GlobalContainer.instance().getTestResult();
		for (PageElement elem : testResult.getElements()) {
			if (elem instanceof Table) {
				Table table = (Table) elem;
				for (Vector<TableCell> line : table.getData()) {
					for (TableCell cell : line) {
						if (cell.getTestResult() == TableCellResult.FAIL
								|| cell.getTestResult() == TableCellResult.EXCEPTION) {
							result = false;
						}
					}
				}
			}
		}
		Log.info("test result is " + result);
		return result;
	}
	
	public static String[] getTestTableTemplates() {
		return new String[] { "|verfiy test result ok|\n" };
	}

}
